#!/bin/bash

# repo：https://github.com/astral-sh/uv

set -euo pipefail

REPO="astral-sh/uv"
API_URL="https://api.github.com/repos/$REPO/releases/latest"

echo "Checking the latest version of uv..."

VERSION=$(curl -s "$API_URL" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/^v//')

if [[ -z "$VERSION" ]]; then
  echo "Error: Could not get version number"
  exit 1
fi

echo "uv latest version: $VERSION"

ASSET=uv-x86_64-unknown-linux-musl.tar.gz
DOWNLOAD_URL="https://github.com/astral-sh/uv/releases/download/$VERSION/$ASSET"

echo "download $ASSET ..."
proxychains4 curl -LS#O "$DOWNLOAD_URL"
